<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:autocomplete="http://java.sun.com/jsf/composite/autocomplete">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:panelGroup rendered="#{!webUserController.hasPrivilege('AdminManagingUsers')}" >
                    <h:outputLabel value="You are NOT authorized"/>
                </h:panelGroup>

                <h:panelGroup rendered="#{webUserController.hasPrivilege('AdminManagingUsers')}" >

                    <h:form>

                        <p:panel >
                            <p:wizard widgetVar="wiz"
                                      flowListener="#{webUserController.onFlowProcess}" style="width: 600px; min-height: 300px;">
                                <p:tab id="tabPerson" title="Personal Details">
                                    <p:panel >
                                        <h:panelGrid columns="2" >
                                            <h:outputText value="Name" ></h:outputText>
                                            <p:inputText autocomplete="off" required="true" value="#{webUserController.current.webUserPerson.name}" ></p:inputText>
                                            <h:outputText value="Address" ></h:outputText>
                                            <p:inputText autocomplete="off" required="true" value="#{webUserController.current.webUserPerson.address}" ></p:inputText>
                                            <h:outputText value="Mobile" ></h:outputText>
                                            <p:inputMask mask="999-9999999" required="true" value="#{webUserController.current.webUserPerson.mobile}" ></p:inputMask>
                                            <h:outputText value="Speciality" ></h:outputText>                                            
                                            <autocomplete:completeSpeciality value="#{webUserController.speciality}"/>
                                        </h:panelGrid>

                                    </p:panel>
                                </p:tab>
                                <p:tab id="tabUser" title="User Details">
                                    <p:panel >
                                        <h:panelGrid columns="2" >
                                            <h:outputText value="User Name"   ></h:outputText>
                                            <p:inputText autocomplete="off" required="true" maxlength="50" value="#{webUserController.current.name }" ></p:inputText>
                                            <h:outputText value="Password" ></h:outputText>
                                            <p:password feedback="true" required="true" maxlength="15" value="#{webUserController.current.webUserPassword}" />

                                            <h:outputText value="Institution" ></h:outputText>
                                            <p:selectOneMenu required="true" value="#{webUserController.institution}" id="ins"  >
                                                <f:selectItem itemLabel="Please select an institutie"/>
                                                <f:selectItems value="#{institutionController.items}" var="i" itemLabel="#{i.name}" itemValue="#{i}" />
                                                <f:ajax render="dept" execute="ins" event="click"/>
                                            </p:selectOneMenu>

                                            <h:outputText value="Department" ></h:outputText>
                                            <p:selectOneMenu id="dept" value="#{webUserController.department}" >
                                                <f:selectItem itemLabel="Please select a Department"/>
                                                <f:selectItems value="#{departmentController.items}" var="d" itemLabel="#{d.name}" itemValue="#{d}" />
                                            </p:selectOneMenu>

                                            <h:outputLabel value="Code" ></h:outputLabel>
                                            <p:inputText autocomplete="off" required="true" value="#{webUserController.current.code}" maxlength="10" ></p:inputText>

                                        </h:panelGrid>


                                    </p:panel>
                                </p:tab>

                                <p:tab id="tabPrivileges" title="Privileges">
                                    <p:panel >
                                        <h:outputText value="Privilages"/>
                                        <p:selectManyCheckbox value="#{webUserController.currentPrivilegeses}" layout="pageDirection" >
                                            <f:selectItems value="#{webUserController.privilegeses}"  />
                                        </p:selectManyCheckbox>
                                    </p:panel>


                                </p:tab>

                                <p:tab id="tabCreate" title="Create">

                                    <p:panel header="Confirm Create User" style="min-height: 300px; padding: 50px; " >
                                        <p:commandButton value="Create User" action="#{webUserController.saveNewUser()}" ajax="false"  onclick="onSubmitButton();"></p:commandButton>
                                    </p:panel>


                                </p:tab>


                            </p:wizard>
                        </p:panel>

                    </h:form>
                </h:panelGroup>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
